
/*
 * Creator:     ML
 * CreatDate:   2019-09-30
 * descripts：医嘱子类设置 -- 查询
 * */
import React from 'react';
import { Form, Row, Col, Input, Select, DatePicker, Button, message,Checkbox } from 'antd';
import { $http } from '../../../containers/config/https';
import '../style/index.less';

const paddRightCol = {
    paddingRight: "0px"
}
const formItemLayoutType = {
    labelCol: { span: 9 },
    wrapperCol: { span: 15 }
}
const formItemLayoutBig = {
    labelCol: { span: 9 },
    wrapperCol: { span: 13 }
}
const formItemLayout = { // label 和input宽度
    labelCol: { span: 9 },
    wrapperCol: { span: 14 }
}
const FormItem = Form.Item;
const Option = Select.Option;
const FindSub = Form.create()(
    class FindSub extends React.Component {
        cacheOriginData = {};
        constructor() {
            super()
            this.state = {
                bigTypeArr:[],
                adviceTypeArr:[],
                checked:true
            }
        }
        componentDidMount() {
            this.props.OnChild(this);
            this.getBigClass()
            this.getAdviceType()
        }
//点击是否生效
changeChecked = (e) => {
    this.setState({
        checked: e.target.checked,
    }, () => {
        this.handleFindSub()
    })
}
//获取大类下拉框
getBigClass=()=>{
            let data = {}
               data = {
                params: [{
                }],
            } 
            $http.post('urlS', this, {
                code: '05100228',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0 &&res.result.Data) {
                        this.setState({
                            bigTypeArr:res.result.Data
                        })
                    }
                }
            })
}
//获取医嘱类别下拉框
getAdviceType=()=>{
    let data = {}
       data = {
        params: [{
        }],
    } 
    $http.post('urlS', this, {
        code: '05100229',
        data: data,
        success: function (res) {
            if (+res.errorCode === 0 &&res.result.Data) {
                this.setState({
                    adviceTypeArr:res.result.Data
                })
            }
        }
    })
}
handleFindSub=()=>{
    this.handleFind(1,20,"init")
}
   //查询医嘱子类
   handleFind=(page,pageSize,mes)=>{
    this.props.form.validateFields((err, values) => {
        if (!err) {
            let checkFlag = ""
            if (mes&&mes!="init") {
                checkFlag = mes
            }
            if (this.state.checked == true) {
                checkFlag = "Y"
            } else {
                checkFlag = "N"
            }
            let data = {}
               data = {
                params: [{
                    code: values.subCode,
                    descripts: values.subDec,
                    ordCatID: values.majorBigClassID,
                    ordTypeID: values.majorType,
                    status: checkFlag,
                }],
                pagination: [{
                    pageSize: parseInt(pageSize),
                    currentPage: parseInt(page),
                }]
            } 
            $http.post('urlS', this, {
                code: '05100227',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        if(mes&&mes=="init"){
                            this.props.findSubTable(res.result.Data,res.result.TotalCount,mes)
                        }else{
                            this.props.findSubTable(res.result.Data,res.result.TotalCount,)
                        }
                    }
                }
            })
        }

    })
}
        render() {
            const { getFieldDecorator } = this.props.form;
            let { topInfo ,bigTypeArr,adviceTypeArr} = this.state
            let typeArr = [{
                code: "01",
                descripts: "医生开嘱",
                descriptsSPCode: "YSKZ",
                enDescripts: "",
                id: "D"
            }, {
                code: "02",
                descripts: "护士开嘱",
                descriptsSPCode: "HSKZ",
                enDescripts: "",
                id: "N"
            },
            //  {
            //     code: "03",
            //     descripts: "补录开嘱(费用)",
            //     descriptsSPCode: "BLKZ",
            //     enDescripts: "",
            //     id: "A"
            // },
            {
                code: "04",
                descripts: "自定价开嘱",
                descriptsSPCode: "ZDJKZ",
                enDescripts: "",
                id: "F"
            },]
            //开医嘱类型
            let typeOp = []
            typeArr && typeArr.map(item => {
                typeOp.push(<Option key={item.id}  value={String(item.id)}>{item.descripts}</Option>)
            })
             //医嘱类别
             let adviceTypeOp = []
             adviceTypeArr && adviceTypeArr.map(item => {
                adviceTypeOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
             })
            
              //医嘱大类
              let bigTypeOp = []
              bigTypeArr && bigTypeArr.map(item => {
                bigTypeOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
              })
            return (
                <div>
                    <Form>
                        <Row gutter={60}>
                            <Col span={8} style={paddRightCol}>
                                <FormItem {...formItemLayoutType} label='代码'>
                                    {getFieldDecorator('subCode', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input onPressEnter={this.handleFindSub}></Input>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={8} style={paddRightCol}>
                                <FormItem {...formItemLayoutType} label='描述'>
                                    {getFieldDecorator('subDec', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Input onPressEnter={this.handleFindSub}></Input>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={8} style={paddRightCol}>
                                <FormItem {...formItemLayoutBig} label='医嘱大类'>
                                    {getFieldDecorator('majorBigClassID', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Select
                                            style={{ width: "100%" }}
                                            allowClear={true}
                                            showSearch={true}
                                            optionFilterProp="role"
                                        >
                                            {bigTypeOp}
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row>
                            <Col span={8} style={paddRightCol}>
                                <FormItem {...formItemLayout} label='医嘱类别'>
                                    {getFieldDecorator('majorType', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Select
                                            style={{ width: "100%" }}
                                            allowClear={true}
                                            showSearch={true}
                                            optionFilterProp="role"
                                        >
                                            {adviceTypeOp}
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={7} style={{ paddingLeft: "42px" }}>
                                <FormItem >
                                    {getFieldDecorator('addCategories', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <Checkbox checked={this.state.checked} onChange={this.changeChecked}>仅显示生效</Checkbox>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={9} style={{ textAlign: "right" }}>
                                <Button type="primary" onClick={this.handleFindSub}>查询</Button>
                            </Col>
                        </Row>

                    </Form>
                </div>
            )
        }
    })
export default FindSub